#define LAND_GRAPHICS_CORE

#include "init.h"

static struct {
	LandGraphics* config;
	LandCanvasBackend* backend;
}ctx = { 0 };

int
landInitCanvasContext(LandGraphics* config, LandCanvasBackend* backend) {
	ctx.config = config;
	ctx.backend = backend;
	return 0;
}

static void
freeCanvas(LandRef* ref) {
	ctx.backend->freeCanvas((LandCanvas*)ref);
}


LAND_GRAPHICS_API LandCanvas*
landNewCanvas(unsigned width, unsigned height, LandMsaa msaa) {
	size_t size = ctx.backend->sizeofCanvas();
	LandCanvas* canvas = landNewRef(size, freeCanvas);
	canvas->width = width;
	canvas->height = height;
	canvas->msaa = msaa;
	ctx.backend->newCanvas(canvas);
	return canvas;
}


LAND_GRAPHICS_API void
landCanvasSize(LandCanvas* canvas, unsigned width, unsigned height) {
	if (canvas->width == width && canvas->height == height) {
		return;
	}
	canvas->width = width;
	canvas->height = height;
	ctx.backend->resizeCanvas(canvas);
}

LAND_GRAPHICS_API void
landCanvasColor(LandCanvas* canvas, LandVector* color) {
	canvas->color = *color;
}

LAND_GRAPHICS_API void
landClearCanvas(LandCanvas* canvas) {
	ctx.backend->clearCanvas(canvas);
}

LAND_GRAPHICS_API void
landFlushCanvas(LandCanvas* canvas) {
	ctx.backend->flushCanvas(canvas);
}